package com.sicocre.actions;

import java.io.Serializable;
import java.util.ArrayList;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.sicocre.beans.Banco;
import com.sicocre.business.service.IBancoService;
import com.sicocre.business.service.IComboService;
import com.sicocre.utils.Constantes;


@Component
@Scope("request")
public class BancoAction implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -8165280871272415805L;

	private static final Logger log = Logger.getLogger(BancoAction.class);

	
	@Autowired
	private IBancoService bancoService;
	@Autowired
	private IComboService comboService;
	
	
	private ArrayList<Banco> listBanco;	
	private Banco banco;
	
	
	public BancoAction(){		
		this.banco = new Banco();
		
	}
	

	@PostConstruct
	public void initForm(){
		this.banco = new Banco();
		listBanco = comboService.consultaBancos(1);
	}
	
	
	public void guardar(){
		log.info("Iniciando proceso de guardado...");
		if(bancoService.insertBanco(banco)){
			FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, Constantes.MSG_SUCCESS, Constantes.MSG_SUCCESS);
            FacesContext.getCurrentInstance().addMessage(null, message);
            
		}else{
			FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, Constantes.MSG_ERROR, Constantes.MSG_ERROR);
            FacesContext.getCurrentInstance().addMessage(null, message);
		}
	}

    public String limpiar(){		
		return "/pages/xhtml/catalogoBancoView.xhtml?faces-redirect=true";
	}

	public IBancoService getBancoService() {
		return bancoService;
	}


	public void setBancoService(IBancoService bancoService) {
		this.bancoService = bancoService;
	}


	public Banco getBanco() {
		return banco;
	}


	public void setBanco(Banco banco) {
		this.banco = banco;
	}


	public ArrayList<Banco> getListBanco() {
		return listBanco;
	}


	public void setListBanco(ArrayList<Banco> listBanco) {
		this.listBanco = listBanco;
	}


	public IComboService getComboService() {
		return comboService;
	}


	public void setComboService(IComboService comboService) {
		this.comboService = comboService;
	}

	
	
	

}
